package com.ruoyi.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.domain.DocumentCategory;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 文档目录树对象
 */
@Data
public class CategoryTree implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 文档id
     */
    private Long documentId;

    /**
     * 文档类型后缀
     */
    private String type;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<CategoryTree> children;

    public CategoryTree() {

    }

    public CategoryTree(DocumentCategory documentCategory) {
        this.id = documentCategory.getId();
        this.label = documentCategory.getCategoryName();
        this.children = documentCategory.getChildren().stream().map(CategoryTree::new).collect(Collectors.toList());
        this.documentId = documentCategory.getDocumentId();
        this.type = documentCategory.getType();
    }

}
